﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.OleDb;
using System.Configuration;
using DCS.Business.Model;
using CarolLib;

namespace DCS.Business
{
   public class OledbDataProvider
    {
       //private static OleDbConnection conn = new OleDbConnection(ConfigurationManager.ConnectionStrings["AccessCon"].ConnectionString);


       private static string connStr = ConfigurationManager.ConnectionStrings["AccessCon"].ConnectionString;


       private static OleDbConnection GetConnection(string monthDir)
       {
           return new OleDbConnection(string.Format(connStr, monthDir));
       }

       /// <summary>
       /// 
       /// </summary>
       /// <param name="MaxExistID"></param>
       /// <returns></returns>
       public static List<SITAMessage> GetNewMessageList(int MaxExistID,string monthDir,string sqlName)
       {
           List<SITAMessage> result=new List<SITAMessage>();
           using (OleDbConnection conn = GetConnection(monthDir))
           {
               conn.Open();
               OleDbCommand cmd = new OleDbCommand(string.Format(ConfigurationManager.AppSettings[sqlName], monthDir,MaxExistID), conn);
              

               using (IDataReader dr = cmd.ExecuteReader())
              {
                  result = DTOHelper.CreateModelList<SITAMessage>(dr);

                  dr.Close();
              }

              conn.Close();
           }
           return result;
       }

    }
}
